<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/11
 * Time: 17:17
 */

namespace app\admin\model;


class UserReport extends DataBase
{

    public function indexData()
    {

        $page_config = array(
            'page' => input('offset', 1),
            'list_rows' => input('limit', 10),
        );

        $data = $this->field('*,count(report_user_id) as report_sum')->group('report_user_id')->order('report_sum DESC')->paginate($page_config);

        foreach($data as $k => $v){

            $userInfo = User::where('user_id','eq',$v['report_user_id'])->field('u_number as u_id,nickname,status,disabled_time')->find();
            $data[$k]['u_id'] = $userInfo['u_id'];
            $data[$k]['nickname'] = $userInfo['nickname'];
            $data[$k]['user_status'] = $userInfo['status'];  //是否被永久禁用
            $data[$k]['status'] = $userInfo['disabled_time'] > time() ? 0 : 1;  //0被禁止，1可用
        }
        return $data;
    }

    public function lookUser()
    {

        $report_user_id = input('user_id');

        $page_config = [
            'page' => input('page', 1),
            'list_rows' => input('limit', 10),
            'query' => [
                'user_id' => $report_user_id
            ]
        ];

        $data = $this->where('report_user_id','eq',$report_user_id)->paginate($page_config);

        //$result = [];
        foreach($data as $k => $v){

            $userInfo = User::where('user_id','eq',$data[$k]['user_id'])->field('u_number as u_id,nickname,u_phone,last_login')->find();
            $data[$k]['u_id'] = $userInfo['u_id'];
            $data[$k]['nickname'] = $userInfo['nickname'];
            $data[$k]['u_phone'] = $userInfo['u_phone'];
            $data[$k]['last_login'] = date('Y-m-d H:i:s',intval($userInfo['last_login']));
            $data[$k]['followers'] = Follower::where('follow_user_id',$data[$k]['user_id'])->count();  //粉丝
            $data[$k]['friends'] = Follower::where('user_id', $data[$k]['user_id'])->count();  //关注的人
            $familyDetail = Family::where([ ['user_id','eq',$data[$k]['user_id']], ['type','eq',1] ])->find();
            if(!empty($familyDetail)) $data[$k]['is_head'] = '是';
            else $data[$k]['is_head'] = '否';

        }

        return $data;
    }

}